class Solution {
public:
    int temperatureTrend(vector<int>& tA, vector<int>& tB) {
        // 在两段区间中找到最长的相同子串问题
        auto rev = [](vector<int>& tA){
        for(int i = tA.size() - 1; i > 0; --i)
            if(tA[i] > tA[i - 1])
                tA[i] = 1;
            else if(tA[i] < tA[i - 1])
                tA[i] = -1;
            else
                tA[i] = 0;
        };
        rev(tA), rev(tB);
        int ans = (tA[1] == tB[1]);
        int now = ans;
        for(int i = 2; i < tA.size(); ++i)
        {
            if(tA[i] == tB[i]) now++;
            else now = 0;
            ans = max(ans, now); 
        }
            
        return ans;
        
    }
};